<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>短信营销3-统计</title>
    <link rel="shortcut icon" href="favicon.ico"> <link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/footable/footable.core.css" rel="stylesheet">
        <link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/dataTables/css/jquery.dataTables.min.css"/>
    <link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/switchery/switchery.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css">
    <link href="<%=path%>/css/mushroom.css" rel="stylesheet">
    <style> 
        .col-sm-1{
            font-weight: normal;
        }  
        table.dataTable tbody th, table.dataTable tbody td{
        padding:10;
        }  
        
          
    </style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="col-md-12 ibox-content">
            <form class="form-horizontal">
                <div class="form-group col-sm-4" id="data_5">
                    <div class="input-daterange input-group" id="datepicker" style="padding-left:15px">
                        <input id="start_time" type="text" class="input-sm form-control" name="start"  readonly="" style="background-color: white;"/>
                        <span class="input-group-addon">到</span>
                        <input id="end_time" type="text" class="input-sm form-control" name="end" readonly="" style="background-color: white;" />
                    </div>
                </div>   
                <div class="col-sm-3">
                    <div class="input-group">
                        <input id="keyWord" type="text" placeholder="批名称搜索" class="input form-control">
                        <span class="input-group-btn">
                            <button onclick="javascript:search();" type="button" class="btn btn btn-primary"> <i class="fa fa-search"></i> 搜索</button>
                        </span>
                    </div>
                </div>
                           
                <div class="col-sm-5">
                    <button onclick="javascript:exportDatas();" class="btn btn-primary pull-right" type="button">导出表单</button>
                </div>
            </form> 
             <div class="col-sm-12" style="margin-top:20px;">
                <div class="ibox float-e-margins">
                    <div class="table-responsive">
                        <table class="display  table-striped table-bordered table-hover" id="mydataTable">
                            <thead>
                                <tr>
                                    <th>项目名称</th>
                                    <th class="sendNum">发送人数</th>
                                    <th class="receiveNum">到达人数</th>
                                    <th class="openNum">点击量</th>
                                    <th class="converNum2">核销人数</th>
                                    <th class="converTotalMoney">核销总额</th>
                                    <th>发送日期</th>
                                </tr>
                            </thead>
                            <tbody>
                               
                            </tbody>
                        </table>
                    </div>                 
                </div>
            </div>
        </div>      
    </div>
    <script src="<%=path%>/hplus/js/jquery.min.js?v=2.1.4"></script>
    <script src="<%=path%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="<%=path%>/hplus/js/plugins/chosen/chosen.jquery.js"></script>
    <script src="<%=path%>/hplus/js/plugins/jsKnob/jquery.knob.js"></script>
    <script src="<%=path%>/hplus/js/plugins/jasny/jasny-bootstrap.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="<%=path%>/hplus/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
    <script src="<%=path%>/hplus/js/plugins/switchery/switchery.js"></script>
    <script src="<%=path%>/hplus/js/plugins/ionRangeSlider/ion.rangeSlider.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="<%=path%>/hplus/js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/clockpicker/clockpicker.js"></script>
    <script src="<%=path%>/hplus/js/plugins/cropper/cropper.min.js"></script>
    
    <script type="text/javascript" src="<%=path%>/hplus/js/plugins/dataTables/jquery.dataTables.min.js"></script>
    <script src="<%=path%>/hplus/js/demo/form-advanced-demo.min.js"></script>
	<script src="<%=path%>/hplus/js/plugins/suggest/bootstrap-suggest.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>

    <script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
	   <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
	   <script type="text/javascript" src="<%=path%>/js/loading.js"></script>
    <script>
	    var path = "<%=path%>";
	    var myDataTable;
	   	var keyWord="";
	   	var startTime="";
	   	var endTime="";
	   	var orderBy="converNum desc";
        var id="";
        $.fn.dataTable.ext.errMode = 'none';
    
        
        $(function(){
        	init();
        	
        });
        
        function init(){
        	id=getQueryString("id");
        	if(!StringEmpty(id)){
        		id="";
        	}
        	
        	myDataTable = dataTable();
        	var myDate = new Date();
        	//获取当前年
        	var year=myDate.getFullYear();
        	//获取当前月
        	var month=myDate.getMonth()+1;
        	var beforeMonth=myDate.getMonth();
        	var beforeYear=year;
        	//获取当前日
        	var day=myDate.getDate(); 
        	if(month>12){
        		year=year+1;
        		month=1;
        	}
        	if(beforeMonth==0){
        		beforeMonth=12;
        		beforeYear=beforeYear-1;
        	}
        	
        	$("#end_time").val(year+"-"+month+"-"+day);
        	$("#end_time").attr("value",year+"-"+month+"-"+day);
        	$("#start_time").attr("value",beforeYear+"-"+beforeMonth+"-"+day);
        	$("#start_time").val(beforeYear+"-"+beforeMonth+"-"+day);
        	
        	$("#start_time").datepicker("setDate",beforeYear+"-"+beforeMonth+"-"+day);
        	$("#end_time").datepicker("setDate",year+"-"+month+"-"+day);
        }
        
        function func_dataTableReload(){
        	myDataTable.ajax.reload(function(){
        		$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green"});
        		$('input').iCheck('uncheck');
        	});
        }
        
        
        function dataTable(){
        	return $('#mydataTable').DataTable({
        		processing: true,
        		ordering: true,
        		searching: false,
        		info: true,
        		autoWidth: true,
        		lengthChange: false,
        	    language: {
        	    	emptyTable: '<div id="content_empty"  class="form-group white-bg" style="text-align:center;padding:120px 0;margin:0;">   <p>暂无短信统计数据</p></div>',
        	    	info: '从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录',
        			infoEmpty: '没有数据',
        			lengthMenu: '每页显示 _MENU_ 条记录',
        			loadingRecords: '正在加载数据....',
        			processing: '正在处理数据....',
        			zeroRecords: '没有找到匹配的记录',
        			paginate: {
        				first: '首页',
        				previous: '前页',
        				next: '后页',
        				last: '尾页'
        			}
        	    },
        	    order: [[4,'desc']],
        		pageLength: 10,
        	    pagingType: 'full_numbers',
        	    columnDefs: [{
       	         'targets' : [0,3,6],    //除第0,3,6列外，都默认不排序
    	         'orderable' : false
                 },{
        			render: function(data, type, full) {
                        var result = '<a class="clickNum" id="'+full.id+'" activityId="'+full.activityId+'"><font color="#1ab394">'+data+'</font></a>';
        				return result;
                    },
        			targets: 3
        		},{
        			render: function(data, type, full) {
                        var result = '<a class="converNum" id="'+full.id+'"><font color="#1ab394">'+data+'</font></a>';
        				return result;
                    },
        			targets: 4
        		} ],
        	    columns: func_columns(),
        	    serverSide: true,
        	    ajax: {
        	    	contentType: 'application/json;charset=utf-8',
        	    	type: 'POST',
        	    	url: func_AjaxUrl(),
        	    	data: function(d){
        	    		d.keyWord=keyWord;
        	    		d.start_time=startTime;
        	    		d.end_time=endTime;
        	    		d.orderBy=orderBy;
        	    		//优惠券批次id
        	    		d.id=id;
        				return JSON.stringify(d);
        			}
        		} ,
        	    "initComplete": function(settings, json) {
        	    	$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
        	    	var info=myDataTable.page.info(); 
                    if(json.error_code=="20028"){
                    	loginDialog();
                    }else{
                    	/* if(info.recordsTotal<1){
                    		createDialog()
                    	} */
                    }     	    	
        	    }
        	});
        	
        }
        /**
         *	设置列名，对应后台
         */
        function func_columns(){
            var jsonArr = [
                {"data":"name"},
                {"data":"sendNum"},
                {"data":"receiveNum"},
                {"data":"clickNum"},
                {"data":"converNum"},
                {"data":"converTotalMoney"},
                {"data":"createTime"},
            ];
            return jsonArr;
        }



        //注券统计列表
        function func_AjaxUrl(){
        	return path+"/socialCouponBatch/ajaxCouponBatchStatistics";
        }

        //导出表单
        function exportDatas(){
            keyWord=$('#keyWord').val();
            startTime=$('#start_time').val();
            endTime=$('#end_time').val();
            window.location.href=path+"/socialCouponBatch/exportCouponBatchForm?keyWord="+encodeURI(encodeURI(keyWord))+"&start_time="+startTime+"&end_time="+endTime+"&orderBy="+orderBy;
        }

        //点击量
        $(document).on('click', '.clickNum', function() {
            var type="";
            var activityId=$(this).attr("activityId");
            if(activityId==0){
                type="coupon";
            }else{
                type="activity";
            }
            window.location.href=path+'/view/coupon/couponBatchClickList?id='+this.id+"&type="+type;
        });

        //核销人数
        $(document).on('click', '.converNum', function() {
            window.location.href=path+'/view/coupon/couponBatchConverList?id='+this.id;
        });

        //搜索
        function search(){
            keyWord=$('#keyWord').val();
            startTime=$('#start_time').val();
            endTime=$('#end_time').val()+" 23:59:59";
            func_dataTableReload();
        }


        

       
        
        $('.sendNum').on('click',function(event){
        	var desc=$(this).attr('aria-sort');
        	if(desc=="nudefined"||desc==undefined)
        		orderBy="sendNum asc";
        	if(desc=="ascending"){
        		orderBy="sendNum desc";
        	}else if(desc=="descending"){
        		orderBy="sendNum asc";
        	}
        	console.log("orderBy0---------->"+orderBy);
        	
        });
        
        $('.receiveNum').on('click',function(event){
        	var desc=$(this).attr('aria-sort');
        	if(desc=="nudefined"||desc==undefined)
        		orderBy="receiveNum asc";
        	if(desc=="ascending"){
        		orderBy="receiveNum desc";
        	}else if(desc=="descending"){
        		orderBy="receiveNum asc";
        	}
        	
        });
        
        $('.openNum').on('click',function(event){
        	var desc=$(this).attr('aria-sort');
        	if(desc=="nudefined"||desc==undefined)
        		orderBy="clickNum desc";
        	if(desc=="ascending"){
        		orderBy="clickNum desc";
        	}else if(desc=="descending"){
        		orderBy="clickNum asc";
        	}
        	console.log("orderBy0---------->"+orderBy);
        	
        });
        
        $('.converNum2').on('click',function(event){
        	var desc=$(this).attr('aria-sort');
        	if(desc=="nudefined"||desc==undefined)
        		orderBy="converNum asc";
        	if(desc=="ascending"){
        		orderBy="converNum desc";
        	}else if(desc=="descending"){
        		orderBy="converNum asc";
        	}
        });
        

        $('.converTotalMoney').on('click',function(event){
        	var desc=$(this).attr('aria-sort');
        	if(desc=="nudefined"||desc==undefined)
        		orderBy="converTotalMoney asc";
        	if(desc=="ascending"){
        		orderBy="converTotalMoney desc";
        	}else if(desc=="descending"){
        		orderBy="converTotalMoney asc";
        	}
        });
        

        
        
        
    </script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
</body>
</html>
